package com.giaothong;

import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;




public class HomeTabActivity extends TabActivity implements OnTabChangeListener{
	public static final int INDEX_TAB_TRAC_NGHIEM = 0;
	public static final int INDEX_TAB_HOC_TRAC_NGHIEM = 1;
	public static final int INDEX_TAB_LY_THUYET = 2;
	public static final int INDEX_TAB_LICH_SU = 3;
	TabHost tabHost;
	private Context context;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
		
		context = this.getApplicationContext();
		
		Resources res = this.getResources();
		tabHost = getTabHost(); // The activity TabHost
		TabHost.TabSpec spec; // Resusable TabSpec for each tab

		spec = tabHost.newTabSpec("tracnghiem").setIndicator("",res.getDrawable(R.drawable.ic_tab_tracnghiem)).setContent(new Intent().setClass(context, TabTracNghiemActivity.class));
		tabHost.addTab(spec);
		
		// Initialize a TabSpec for each tab and add it to the TabHost
		spec = tabHost.newTabSpec("hoctracnghiem").setIndicator("",res.getDrawable(R.drawable.ic_tab_hoctracnghiem)).setContent(new Intent().setClass(context, TabHocTracNghiemActivity.class));
		tabHost.addTab(spec);

		// Initialize a TabSpec for each tab and add it to the TabHost
		spec = tabHost.newTabSpec("lythuyet").setIndicator("", res.getDrawable(R.drawable.ic_tab_lythuyet)).setContent(new Intent().setClass(context, TabLyThuyetActivity.class));
		tabHost.addTab(spec);

		// Points tabs
		spec = tabHost.newTabSpec("lichsu").setIndicator("", res.getDrawable(R.drawable.ic_tab_lichsu)).setContent(new Intent().setClass(this, Expextends.class));
		tabHost.addTab(spec);

		// Social tabs
		spec = tabHost.newTabSpec("caidat").setIndicator("", res.getDrawable(R.drawable.ic_setting)).setContent(new Intent().setClass(context, TabSettingsActivity.class));
		tabHost.addTab(spec);

		// Contact tabs
		tabHost.setCurrentTab(Main.getIndexTab().getIndexCurrentTab());
		
		this.tabHost.setOnTabChangedListener(this);
		
		
	}	
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub

		AlertDialog.Builder ab = new AlertDialog.Builder(context);
		ab.setMessage(getResources().getString(R.string.quit_confirm));
		ab.setPositiveButton(getResources().getString(R.string.yes),
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						finish();
					}
				});
		ab.setNegativeButton(getResources().getString(R.string.no),
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						dialog.dismiss(); 
					}
				});
		ab.show();
	}
	@Override
	public void onTabChanged(String tabId) {
		// TODO Auto-generated method stub
		int indexCurrentTab = this.tabHost.getCurrentTab();
		switch(indexCurrentTab){
		case 0:
			Main.getIndexTab().setIndexCurrentTab(INDEX_TAB_TRAC_NGHIEM);
			break;
		case 1:
			Main.getIndexTab().setIndexCurrentTab(INDEX_TAB_HOC_TRAC_NGHIEM);
			break;
		case 2:
			Main.getIndexTab().setIndexCurrentTab(INDEX_TAB_LY_THUYET);
			break;
		case 3:
			Main.getIndexTab().setIndexCurrentTab(INDEX_TAB_LICH_SU);
			break;
		
		}
	}

	
}
